
export default class Vec3 {
    x = 0;
    y = 0;
    z = 0;
    constructor(x = 0, y = 0, z = 0) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    add(v) {
        this.x += v.x;
        this.y += v.y;
        this.z += v.z;
        return this;
    }
    sub(v) {
        this.x -= v.x;
        this.y -= v.y;
        this.z -= v.z;
        return this;
    }
    mul(s) {
        this.x *= s;
        this.y *= s;
        this.z *= s;
        return this;
    }
    length() {
        return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
    }
    lengthSquared() {
        return this.x * this.x + this.y * this.y + this.z * this.z;
    }
    toArray() {
        return [this.x, this.y, this.z];
    }
    normalize() {
        let len = this.length();
        return new Vec3(this.x / len, this.y / len, this.z / len);
    }
    static fromArray(arr) {
        return new Vec3(arr[0], arr[1], arr[2]);
    }
    static subtract(a: Vec3, b: Vec3) {
        return new Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
    }
    static cross(a: Vec3, b: Vec3) {
        return new Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
    }
    static dot(a: Vec3, b: Vec3) {
        return a.x * b.x + a.y * b.y + a.z * b.z;
    }
}